home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
picklst.exe
/
TEST.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1991-07-26
|
7KB
|
229 lines
program Test;
{A general program for testing new objects. This demonstrates TPickDialog
and TTextDialog.}
{********************************}
{***Programmed by ***}
{***Blake Watson ***}
{***CIS number 70303,373 ***}
{********************************}
uses App, Menus, Objects, Drivers, Gadgets, Views, Memory,
Objects1, Dialogs1;
type
Main = object(TApplication)
Clock: PClockView;
Heap : PHeapView;
constructor Init;
procedure InitMenuBar; virtual;
procedure Idle; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
end;
const
cmObjectA = 100; cmObjectB = 101; cmObjectC = 102; cmObjectD = 103;
cmObjectE = 104; cmObjectF = 105; cmObjectG = 106; cmObjectH = 107;
function HSB(r:trect): pScrollBar;
begin
r.assign(r.a.x, r.b.y, r.b.x, r.b.y+1);
HSB := New(pScrollBar, init(R));
end;
function VSB(R:tRect): pScrollBar;
begin
r.Assign(r.b.x, r.a.y, r.b.x+1, r.b.y);
VSB := New(pScrollBar, init(R));
end;
constructor Main.Init;
var R: TRect;
begin
TApplication.Init;
GetExtent(R);
R.A.X := R.B.X - 9; R.B.Y := R.A.Y + 1;
Clock := New(PClockView, Init(R));
Insert(Clock);
GetExtent(R);
Dec(R.B.X);
R.A.X := R.B.X - 9; R.A.Y := R.B.Y - 1;
Heap := New(PHeapView, Init(R));
Insert(Heap);
end;
procedure Main.Idle;
begin
TApplication.Idle;
Clock^.Update;
Heap^.Update;
end;
procedure Main.InitMenuBar;
var R: TRect;
begin
R.Assign(0,0,80,1);
MenuBar := New(PMenuBar, Init(R, NewMenu(
NewSubMenu('~T~ests', 0, NewMenu(
NewItem('Object ~A~', '', 0, cmObjectA, 0,
NewItem('Object ~B~', '', 0, cmObjectB, 0,
NewItem('Object ~C~', '', 0, cmObjectC, 0,
NewItem('Object ~D~', '', 0, cmObjectD, 0,
NewItem('Object ~E~', '', 0, cmObjectE, 0,
NewItem('Object ~F~', '', 0, cmObjectF, 0,
NewItem('Object ~G~', '', 0, cmObjectG, 0,
NewItem('Object ~H~', '', 0, cmObjectH, 0,
nil))))))))),
nil))));
end;
procedure Main.HandleEvent;
var W: PWindow;
R: TRect;
H,V: PScrollBar;
procedure ObjectA;
var L: PSelectCollection;
P: PPickDialog;
W: Word;
begin
L := New(PSelectCollection, Init('10,Test,1'));
{The string passed to TSelectCollection.Init has the number of items
in the list, the name of the list, and the number of items selectable.
This may seem an unusual way to pass parameters, but it anticipates
TTextDialog, which reads in the string from a text file.}
L^.NewItem('1) Item One'); L^.NewItem('2) Item Two'); L^.NewItem('3) Item Three');
L^.NewItem('4) Item Four'); L^.NewItem('5) Item Five'); L^.NewItem('6) Item Six');
L^.NewItem('7) Item Seven'); L^.NewItem('8) Item Eight'); L^.NewItem('9) Item Nine');
L^.NewItem('A) Item A');
{The list, naturally, may be created in any fashion one wishes, as long
as it is a TSelectCollection. The code is "minimal fuss" code. It is
highly mouse sensitive, tracking the mouse moves. A click on an item
when only one item may be selected causes TPickDialog to delete itself.
This eliminates the need for pressing additional "OK" buttons. Also,
pressing the first letter of an item will select that item! In this
version of the code, an keystroke with no corresponding item will select
whatever item the highlight bar is currently on.}
P := New(PPickDialog, Init(L, 10,10));
W := ExecView(ValidView(P));
{One item in L will have its selected field toggled on.}
Dispose(L, Done);
If P<>nil then Dispose(P, Done);
end;
procedure ObjectB;
var L: PSelectCollection;
P: PPickDialog;
W: Word;
begin
L := New(PSelectCollection, Init('10,Test,2'));
{Here's the same thing, with two items selectable. Return or a right
mouse click will end the dialog.}
L^.NewItem('1) Item One'); L^.NewItem('2) Item Two'); L^.NewItem('3) Item Three');
L^.NewItem('4) Item Four'); L^.NewItem('5) Item Five'); L^.NewItem('6) Item Six');
L^.NewItem('7) Item Seven'); L^.NewItem('8) Item Eight'); L^.NewItem('9) Item Nine');
L^.NewItem('A) Item A');
P := New(PPickDialog, Init(L, 10,10));
W := ExecView(ValidView(P));
{Two items in L will have its selected field toggled on. You could then
say,}
L^.DropNotSelected;
{Which would dispose of all the items not selected by the user.}
Dispose(L, Done);
If P<>nil then Dispose(P, Done);
end;
procedure ObjectC;
var L: PSelectCollection;
P: PTextDialog;
W: WOrd;
begin
P := New(PTextDialog, Init(pointer(L),5,5,'SAMPLE.TXT','List 1'));
{This takes "List 1" out of the SAMPLE.TXT text file. TTextDialog is
case sensitive. It builds the list from string items following a header,
which matches the "NoItems,Name,NoToSelect" format given for
TSelectCollection.}
W := ExecView(ValidView(P));
{L will come back with the entire list! Not just selected items. L is passed
generic pointer to allow for future expansion, where L might change. As
I wrote this object when first learning TV, I found it necessary to do
so for future objects where L was a descendant of PSelectCollection.}
If L<>nil then Dispose(L, Done);
{If SAMPLE.TXT or "List 1" does not exist, L will never be initialized.}
If P<>nil then Dispose(P, Done);
end;
procedure ObjectD;
var L: PSelectCollection;
P: PTextDialog;
W: WOrd;
begin
{The following code is identical to the code for Object C, except that
a different list is specified.}
P := New(PTextDialog, Init(pointer(L),5,5,'SAMPLE.TXT','List 2'));
W := ExecView(ValidView(P));
If L<>nil then Dispose(L, Done);
If P<>nil then Dispose(P, Done);
end;
procedure ObjectE;
begin
end;
procedure ObjectF;
begin
end;
procedure ObjectG;
begin
end;
procedure ObjectH;
begin
end;
begin
If Event.What = evCommand then
begin
case Event.Command of
cmObjectA: ObjectA;
cmObjectB: ObjectB;
cmObjectC: ObjectC;
cmObjectD: ObjectD;
cmObjectE: ObjectE;
cmObjectF: ObjectF;
cmObjectG: ObjectG;
cmObjectH: ObjectH;
end
end;
TApplication.HandleEvent(EVent);
end;
var M: Main;
begin
M.Init;
M.Run;
M.DOne;
end.